package thread;


@FunctionalInterface
interface Action<T>{
    void execute(T t);
}

public class Test11_function {
    public static void main(String[] args) {
        //外部类
        Action a = new MyAction();
        a.execute("100");

        //匿名内部类
        Action a1 = new Action() {
            @Override
            public void execute(Object o) {
                System.out.println(o);
            }
        };
        a1.execute("200");

        //lambda语法
        Action a2 = (t)->{
            //处理...
            System.out.println(t);
        };
        a2.execute("300");

        //直接绑定
        Action a3 = System.out::println;
        a3.execute("400");

        //作为参数用
        test(System.out::println,"500");
    }
    static void test(Action a,String s){
        a.execute(s);
    }
}

class MyAction implements Action {

    @Override
    public void execute(Object o) {
        System.out.println(o);
    }
}